#include <stdio.h>
#include "status.h"
#include "ram.h"

long double
get_ram(Arg * arg)
{
    FILE * file;
    unsigned int total, free, buffers, cached;

    if (!(file = fopen("/proc/meminfo", "r"))) {
        printf("can't open /proc/meminfo\n");
        return 0.0;
    }

    fscanf(file, "MemTotal: %u kB\nMemFree: %u kB\nMemAvailable: %u kB\nBuffers: %u kB\nCached: %u kB\n",
    &total, &free, &buffers, &buffers, &cached);

    fclose(file);
    return 100 * ((long double) (total - free) - (buffers + cached)) / total;
}
